package com.bzkj.web.controller.basic;

import com.bzkj.basicinfo.domain.basic.BasicStoArea;
import com.bzkj.basicinfo.service.basic.BasicStoAreaService;
import com.bzkj.common.annotation.LogC;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.core.text.Convert;
import com.bzkj.common.enums.BusinessType;
import com.bzkj.common.utils.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.bzkj.common.core.page.TableSupport.PAGE_NUM;
import static com.bzkj.common.core.page.TableSupport.PAGE_SIZE;

/**
 * @Author swj
 * @ClassName BasicStoAreaController
 * @Date 2024/12/13 11:46:49
 * @description 库区信息
 */
@RestController
@RequestMapping("basic/stoArea")
public class BasicStoAreaController extends BaseController {
    @Autowired
    private BasicStoAreaService basicStoAreaService;

    /**
     * 查询货区信息
     *
     * @Author wangzhichao
     * @Date 2024/12/13 11:56:46
     * @Param entity
     */
    @PreAuthorize("@ss.hasPermi('index:region:query')")
    @GetMapping("findStoArea")
    public TableDataInfo findStoArea(BasicStoArea entity) {
        startPage();
        return getDataTable(basicStoAreaService.findStoArea(entity));
    }

    /**
     * 查询erp库区信息
     *
     * @param entity
     * @return
     */
//    @PreAuthorize("@ss.hasPermi('index:region:query')")
    @GetMapping("/findErpMapList")
    public TableDataInfo findErpMapList(BasicStoArea entity) {
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
        return basicStoAreaService.selectErpMapStockList(entity,pageNum,pageSize);
    }
    @GetMapping("/findErpStock")
    public AjaxResult findErpStock(BasicStoArea entity) {
        return basicStoAreaService.selectErpStock(entity);
    }

//    @PreAuthorize("@ss.hasPermi('index:region:add')")
    @PostMapping("/insertWmsErpStockMap")
    public AjaxResult insertWmsErpStockMap(@RequestBody BasicStoArea entity) {
        return basicStoAreaService.insertErpMap(entity);
    }
    @PostMapping("/insertJiXingMap")
    public AjaxResult insertJiXingMap(@RequestBody BasicStoArea entity) {
        return basicStoAreaService.insertJiXingMap(entity);
    }

    @PostMapping("/deleteErpMap")
    public AjaxResult deleteErpMap(@RequestBody BasicStoArea entity) {
        return basicStoAreaService.deleteErpMap(entity);
    }
    /**
     * 查询所有剂型信息
     *
     * @Author wangzhichao
     * @Date 2024/12/13 11:56:46
     * @Param entity
     */
    @PreAuthorize("@ss.hasPermi('index:region:query')")
    @GetMapping("/findStoAreaList")
    public TableDataInfo findStoAreaList(BasicStoArea entity) {
        startPage();
        return getDataTable(basicStoAreaService.findStoAreaList(entity));
    }
    @PreAuthorize("@ss.hasPermi('index:region:query')")
    @GetMapping("/findStoAreaAll")
    public List<BasicStoArea> findStoAreaAll(BasicStoArea entity) {
        return basicStoAreaService.findStoAreaList(entity);
    }

    @PreAuthorize("@ss.hasPermi('index:region:query')")
    @GetMapping("/findAllStoAreaList")
    public List<BasicStoArea> findAllStoAreaList(BasicStoArea entity) {
        return basicStoAreaService.findAllStoAreaList(entity);
    }

    @PreAuthorize("@ss.hasPermi('index:region:add')")
    @PostMapping("/addStoArea")
    public AjaxResult addStoArea(@RequestBody BasicStoArea entity) {
        return basicStoAreaService.addStoArea(entity);
    }

    @PreAuthorize("@ss.hasPermi('index:region:edit')")
    @PostMapping("/updateStoArea")
    public AjaxResult updateStoArea(@RequestBody BasicStoArea entity) {
        return basicStoAreaService.updateStoArea(entity);
    }

    @PreAuthorize("@ss.hasPermi('index:region:delete')")
    @DeleteMapping("/deleteStoArea")
    public AjaxResult addStoArea(String stoAreaId) {
        return basicStoAreaService.deleteStoAreaById(stoAreaId);
    }

    @PreAuthorize("@ss.hasPermi('index:region:stateEdit')")
    @PutMapping("/updateState")
//    @LogC(title = "货区管理", businessType = BusinessType.UPDATE, pkFieldNames = "sto_area_id",
//            tableNames = "basic_sto_area"
//    )
    public AjaxResult updateBasicStoAreaEnableStatus(@RequestParam("ckzht") String ckzht, @RequestParam("hw") String hw) {
        return basicStoAreaService.updateBasicStoAreaEnableStatus(ckzht, hw);
    }

    @PreAuthorize("@ss.hasPermi('index:region:stateEdit')")
    @PutMapping("/updateStoAreaState")
    @LogC(title = "剂型管理", businessType = BusinessType.UPDATE, pkFieldNames = "id",
            tableNames = "basic_formulation_info"
    )
    public AjaxResult updateStoAreaState(@RequestParam("enableState") String enableState, @RequestParam("id") String id) {
        return basicStoAreaService.updateBasicStoAreaStatus(enableState, id);
    }

}
